package binary_tree

// 输入两颗二叉树A和B  判断B是不是A的子结构 子树

func HasSubtree(a, b *TreeNode) bool {
	var result bool
	if a != nil && b != nil {
		if a.val == b.val {
			result = DoesTree1HaveTree2(a, b)
		}
		if !result {
			result = HasSubtree(a.left, b)
		}
		if !result {
			result = HasSubtree(a.right, b)
		}
	}
	return result
}

func DoesTree1HaveTree2(a, b *TreeNode) bool {
	if b == nil {
		return true
	}
	if a == nil {
		return false
	}
	if !(a.val == b.val) {
		return false
	}
	return DoesTree1HaveTree2(a.left, b.left) && DoesTree1HaveTree2(a.right, b.right)
}

// 判读两个浮点数是否相等

func equal(v1, v2 float64) bool {
	if v1-v2 > -0.000000001 && v1-v2 < 0.000000001 {
		return true
	} else {
		return false
	}
}
